package com.asset.common.enums;

import java.util.Arrays;

/**
 * @author luoyongzhi
 */
public enum ResultCodeEnum {

    SUCCESS(0, "成功"),
    FAIL(1, "失败"),
    ;

    private Integer code;
    private String name;

    private ResultCodeEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static ResultCodeEnum getEnum(Integer code) {
        if (code == null) {
            return null;
        }
        return Arrays.stream(ResultCodeEnum.values())
                .filter(en -> en.getCode().equals(code)).findAny().orElseGet(null);
    }
}
